<template>
    <div>
        <section class="login_message">
            <input type="text" maxlength="11" placeholder="请输入绑定手机号码" v-model="phone">
        </section>
        <phoneCode :phone="phone" type="Y" @setPhone="setPhone"></phoneCode>
        <section class="login_message">
            <input type="password" placeholder="请输入密码" maxlength="12" v-model="pwd">
        </section>
        <section class="login_message">
            <input type="password" placeholder="请再次输入密码" maxlength="12" v-model="ckpwd">
        </section>
        <section class="login_message">
            <mt-button class="btn" @click="reset">重置</mt-button>
        </section>
    </div>
</template>
<script>
import phoneCode from '../components/phoneCode'
import {rePwd} from '../api'
import {Toast} from 'mint-ui'
export default {
    data() {
        return {
            phone:'',
            pwd:'',
            code:'',
            ckpwd:''
        }
    },
    components:{phoneCode},
    methods:{
        setPhone(data){
            this.code = data;
        },
        reset(){
            const data = {
                phone:this.phone,
                code:this.code,
                pwd:this.pwd,
                ckpwd:this.pwd,
                type:1
            }
            let reg = /^[a-zA-Z0-9_-]{6,12}$/
            if(!/^1[3-9]\d{9}$/.test(this.phone)){
              Toast('手机号码格式错误')
              return;
            }else if(!data.code){
                Toast('请输入验证码')
                return;
            }else if(!data.pwd){
                Toast('请输入密码');
                return;
            }else if(!data.ckpwd){
                Toast('请再次输入密码');
                return
            }else if(data.pwd!==data.ckpwd){
                Toast('两次密码不一致')
                return;
            }
            rePwd(data).then(res=>{
                Toast(res.msg);
                if(res.code == 200){
                    this.$router.push('/');
                }
            })
        }
    }
}
</script>
<style scoped>
    .btn {
        background: #F0463C;
        width: 80%;
        color: white;
        height: 3rem;
        font-size: 1rem;
        margin: 1rem auto;
        border-radius: 0.15625rem;
    }
</style>